<template>
      <div id="goodslist">
            <page-title><span slot="pageName">用户反馈</span></page-title>
                  <div class="box">
                        <el-button class="uploadGoods" type="" round @click="getQuesten">全部反馈</el-button>
                        <el-button class="uploadGoods" type="" round @click="type = 1">已处理</el-button>
                        <el-button class="uploadGoods" type="success" round @click="type = 2">未处理</el-button>
                  </div>
            <!-- 表格 -->
              <el-table
                  :data="tableData"
                  style="width: 100%"
                  border
                  :height="height"
                  stripe
                  align="center"
                  :row-class-name="tableRowClassName">
                        <el-table-column
                              prop="addtime"
                              align="center"
                              label="反馈时间"
                              >
                        </el-table-column>
                        

                        <el-table-column
                              prop="signboard"
                              align="center"
                              label="发布者">
                              <template slot-scope="scope">
                                    {{ scope.row.realname ? scope.row.realname : scope.row.wnickname }}
                              </template>
                        </el-table-column>

                       

                        <el-table-column
                              prop="phone"
                              align="center"
                              label="手机号码">
                        </el-table-column>

                        <el-table-column
                              prop="content"
                              align="center"
                              label="反馈内容">
                        </el-table-column>

                        <el-table-column
                              prop="status"
                              align="center"
                              label="状态">
                              <template slot-scope="scope">
                                   <el-button  size="mini"  :type=" scope.row.status == 1 ? 'success' : 'danger'  ">
                                         {{ scope.row.status == 1 ? "已处理" : "未处理" }}
                                   </el-button>
                              </template>
                        </el-table-column>

                        <el-table-column prop="cardNum" align="center" label="操作">
                              <template slot-scope="scope">
                                    <el-button
                                    size="mini"
                                    type="primary"
                                    @click="editProject(scope.row)">标记已处理</el-button>
                              </template>
                        </el-table-column>
                  </el-table>
                  <!-- 分页 -->
                  <div class="page">
                        <el-pagination
                        background
                        layout="prev, pager, next"
                        :page-size="pageSize"
                        :current-page="currentPage"
                        @current-change="pageChange"
                        :total="total">
                        </el-pagination>
                  </div>
                  <!-- <li-liao :DialogData="DialogData" :FormData="FormData" @update="getProject" ></li-liao> -->
      </div>
</template>

<script>
      import PageTitle from '@/components/PageTitle'
    //   import LiLiao from '@/components/Goods/LiLiao'
      export default {
            data() {
                  return {
                        tableData: [],
                        DialogData: {
                              title: "",
                              show: false,
                              add: false
                        },
                        FormData: {
                              id: "",
                              title: "",
                              score: ""
                        },
                        allData: [],
                        type: "",
                        currentPage: 1,
                        pageSize: 10,
                        total: 0,
                  }
            },
            components: {
                  PageTitle,
                //   LiLiao
            },
            computed: {
                  token() {
                        return this.$store.state.token; 
                  },
                  height() {
                        return this.$store.state.height;
                  }
            },
            mounted () {
                  this.getQuesten();
            },
           
            methods: {
                  
            //      获取所有用户反馈
                  async getQuesten( pages ) {
                        let token = localStorage.miniToken 
                        let page = pages ? pages : 1
                        let res = await this.$axios.post("/admin/user/feedback", { token , page } )
                        console.log(res);
                        
                        this.tableData = res.data.data
                        // this.allData = res.data.data
                        this.total = this.tableData[0].count ?  this.tableData[0].count : 0;
                  },

               
                  tableRowClassName({row, rowIndex}) {
                        if (rowIndex === 1) {
                              return 'warning-row';
                        } else if (rowIndex === 3) {
                              return 'success-row';
                        }
                              return '';
                  },
            //      标记已处理
                  async editProject( row ) {
                        if (row.status == 1) {
                              this.$message.success("该数据已标记")
                              return false
                        } else {
                              let res = await this.$axios.post("/admin/user/feedbackchange", { token: this.token, id: row.id })
                              let code = res.data.code 
                              if (code == 204) {
                                    this.$message.success("更新成功")
                                    this.getQuesten()
                              } else {
                                    this.$message.error("更新失败")
                                    this.getQuesten()
                              }
                        }
                        
                  },
                  // 页码变化
                  pageChange( page ) {
                        this.getQuesten()
                  },

            },
      }
</script>

<style lang="scss" scoped>
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  .btn {
        text-align: left;
        margin-top: 30px;
  }
  .addProject {
        float: right;
        margin: 10px 20px;
  }
    .box {
  width: 100%;
  text-align: left;
  padding-bottom: 30px;
}
.page {
       padding: 20px;
       text-align: right;
 }
</style>